//
//  HomePageDetailHeaderView.m
//  ShowYork
//
//  Created by hxh on 2021/2/24.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "HomePageDetailHeaderView.h"

@interface HomePageDetailHeaderView ()
@property (nonatomic,strong)UILabel *titleLb; /// 显示时间或者数量createTimeLb
@property (nonatomic,strong)UIButton *shareBtn; /// 查看更多按钮
@property (nonatomic,strong)UIImageView *shareImgView; /// 查看更多背景图片
@property (nonatomic,strong)UIImageView *removeImgView; /// 删除按钮
@property (nonatomic,strong)UIButton *removeBtn; ///
//@property (nonatomic,strong)CAGradientLayer *gradientLayer; /// 头部视图的渐变层

@property (nonatomic,strong)UIView *toolView;

@end


@implementation HomePageDetailHeaderView


- (instancetype)initWithItemModel:(HomeTagItemModel *)itemModel showDateTime:(BOOL)showDateTime{
    if (self = [super init]) {
        [self setUI];
        
    }
    return self;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.frame = CGRectMake(0, 0, kScreenW, kNavBarHeight);

    
    self.toolView = [[UIView alloc]init];
    [self addSubview:self.toolView];
    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(kNavStatusBarHeight);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(44);
    }];
    
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.textColor = RGBA(255, 255, 255, 1);
    self.titleLb.numberOfLines = 2;
    self.titleLb.textAlignment = NSTextAlignmentCenter;
    self.titleLb.font = [UIFont boldSystemFontOfSize:18];
    [self.toolView addSubview:self.titleLb];
    
    self.titleLb.layer.shadowColor   = RGBA(240, 240, 240, 1).CGColor;
    self.titleLb.layer.shadowOffset  = CGSizeMake(0, 0);
    self.titleLb.layer.shadowOpacity = 0.8;
    self.titleLb.layer.shadowRadius  = 4;

//    self.titleLb.layer.masksToBounds = YES;
            
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.toolView);
        make.centerY.equalTo(self.toolView);
    }];
    
    self.removeImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_head_remove_tag"]];
    [self.toolView addSubview:self.removeImgView];
    [self.removeImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.toolView);
        make.left.equalTo(self.toolView).offset(16);
    }];
    
    self.removeBtn = [[UIButton alloc]init];
    [self.removeBtn addTarget:self action:@selector(removeMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.toolView addSubview:self.removeBtn];
    [self.removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.toolView);
        make.left.equalTo(self.toolView);
        make.right.equalTo(self.removeImgView.mas_right).offset(16);
    }];
    
    self.shareImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_head_share_tag"]];
    
    [self.toolView addSubview:self.shareImgView];
    [self.shareImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.toolView);
        make.right.equalTo(self.toolView).offset(-16);
    }];
    
    self.shareBtn = [[UIButton alloc]init];
    [self.shareBtn addTarget:self action:@selector(shareMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.toolView addSubview:self.shareBtn];
    [self.shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.toolView);
        make.right.equalTo(self.toolView);
        make.left.equalTo(self.shareImgView.mas_left).offset(-16);
    }];
}

- (void)removeMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(homePageRemoveAction)]) {
        [self.delegate homePageRemoveAction];
    }
}

- (void)shareMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(homePageShareAction)]) {
        [self.delegate homePageShareAction];
    }
}

- (void)showIndexWithCurrentItemModel:(HomePageItemModel *)itemModel{

    BOOL isStatus = NO;
    
    if ([[RPAppManager getCustomerId] isEqualToNumber:itemModel.userId]) {
        isStatus = itemModel.isDisplay.intValue == 1;
    }else{
        isStatus = YES;
    }
    
    NSString *str = isStatus?@"":@"审核中";
    
    self.shareBtn.userInteractionEnabled = isStatus;
    self.shareImgView.image = [UIImage imageNamed:isStatus?@"home_detail_head_share_tag":@"home_share_disable_tag"];
    
    
    if (itemModel.maxCount == 0 || itemModel.maxCount == 1) {
        self.titleLb.text = str;
    }else{
        if (str.length == 0) {
            self.titleLb.text = [NSString stringWithFormat:@"%ld/%ld",(long)itemModel.currentIndex+1,(long)itemModel.maxCount];
        }else{
            self.titleLb.text = [NSString stringWithFormat:@"%ld/%ld\n%@",(long)itemModel.currentIndex+1,(long)itemModel.maxCount,str];
        }
    }

    if (itemModel.contentType.intValue == 1) {
        [MobClick event:@"homeDetail_text_type"];
    }
    if (itemModel.contentType.intValue == 2) {
        [MobClick event:@"homeDetail_image_type"];
    }
    if (itemModel.contentType.intValue == 3) {
        [MobClick event:@"homeDetial_video_type"];
    }
}

   
@end
